#include <Arduino.h>
#include <ALIBELCD.h>
#include <SoftwareSerial.h>

	// RX is unused
	SoftwareSerial myLCD(LCD_RX_PIN, LCD_TX_PIN); 

	ALIBELCD::ALIBELCD(){
		// set the data rate for the SoftwareSerial port
        // LCD is set up at 19200 br
		myLCD.begin(LCD_BAUDRATE);
	}
	bool ALIBELCD::backlightOn(){
		myLCD.write(LCD_CMD_BL_ON);
	}
	bool ALIBELCD::backlightOff(){
		myLCD.write(LCD_CMD_BL_OFF);
	}
	bool ALIBELCD::clearScreen(){
		myLCD.write(LCD_CMD_CLEAR_SCREEN);
		delay(5);
	}
	bool ALIBELCD::displayOff(){
		backlightOff();
		myLCD.write(LCD_CMD_DISP_OFF);
	}
	bool ALIBELCD::displayOnNoCursor(){
		myLCD.write(LCD_CMD_DISP_ON_NO_CURSOR);
	}
	bool ALIBELCD::displayOnBlinkingCursor(){
		myLCD.write(LCD_CMD_LINE_FEED);
	}
	bool ALIBELCD::lineFeed(){
		myLCD.write(LCD_CMD_DISP_ON_BLINK_CURSOR);
	}
	bool ALIBELCD::carriageReturn(){
		myLCD.write(LCD_CMD_CARRIAGE_RETURN);
	}
	bool ALIBELCD::moveCursorLeft(){
		myLCD.write(LCD_CMD_BACKSPACE);
	}
	bool ALIBELCD::moveCursorRight(){
		myLCD.write(LCD_CMD_NEXT_SPACE);
	}
	bool ALIBELCD::_moveToRow1Col1(){
		myLCD.write(LCD_CMD_R1C1);
	}
	bool ALIBELCD::_moveToRow2Col1(){
		myLCD.write(LCD_CMD_R2C1);
	}
	bool ALIBELCD::_writeTextToLCD(String textToWrite){
		
		String paddedTextToWrite;
		textToWrite.trim();
		paddedTextToWrite=textToWrite;

		for(int i =paddedTextToWrite.length(); i<16; i++){
			paddedTextToWrite += "-";
		}
		myLCD.println(paddedTextToWrite);
	}
	
	bool ALIBELCD::writeTextAtRow1(String textToWrite){
		_moveToRow1Col1();
		_writeTextToLCD(textToWrite);
	}
	bool ALIBELCD::writeTextAtRow2(String textToWrite){
		_moveToRow2Col1();
		_writeTextToLCD(textToWrite);
	}
	